#include<iostream>
using namespace std;
extern "C"
{
    #include"../StackC/stack.h"
}
bool isValid(const char* s) {
    int size = strlen(s);
    Stack st;
    StackInit(&st);
    bool isMatch = true;
    for (int i = 0; i < size; ++i)
    {
        if (('(' == s[i]) || ('[' == s[i]) || ('{' == s[i]))
        {
            StackPush(&st, s[i]);
        }
        else
        {
            if (StackEmpty(&st))
            {
                //StackDestroy(&st);
                //return false;
                isMatch = false;
                break;
            }


            char top = StackTop(&st);
            if ((top == '(' && s[i] == ')') ||
                (top == '[' && s[i] == ']') ||
                (top == '{' && s[i] == '}'))
            {
                StackPop(&st);
            }
            else
            {
                isMatch = false;
                break;
            }
        }
    }


    if (!StackEmpty(&st))
    {
        //StackDestroy(&st);
        //return false;
        isMatch = false;
    }


    StackDestroy(&st);
    return isMatch;
}
int main()
{
    cout << isValid("{[]}()") << endl;
	return 0;
}